var request = require('../../utils/request.js');
// pages/ comment/ comment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      cid:'',
      inputContent:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    // console.log(options.cid)
    that.setData({
      cid: options.cid,
    });
  },
  // 获取文本域内容
  bindTextAreaBlur: function (e) {
    this.setData({
      inputContent: e.detail.value
    });
    // console.log(e.detail.value)
  },
  // 提交评论
  tijiao:function(e){
      var that = this
      var cid = that.data.cid
      var session3rd = wx.getStorageSync('session3rd');
      var nickName = wx.getStorageSync('nickName');
      var avatarUrl = wx.getStorageSync('avatarUrl');
      // var inputContent = that.data.inputContent
      console.log(session3rd)
      if (that.data.inputContent == ''){
        wx.showToast({
          title: '评价不能为空',
          image: '/image/fail.png',
          duration: 1500
        })
        return false
      }else{
        wx.request({
          url: request.dataUrl + '/Orchard/add_comment',
          method: "POST",
          data: {
            header_pic: avatarUrl,
            nickname: nickName,
            content: that.data.inputContent,
            cid: cid,
            token: session3rd
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (data) {
            console.log(data)
            wx.showToast({
              title: '评价成功',
              image: '/image/success.png',
              duration: 1500,
              success: () => {
                setTimeout(() => {
                  wx.navigateBack();
                }, 2000)
              }
            })
          }
        })
      }
      // console.log(cid)
      // console.log(session3rd)
      // console.log(nickName)
      // console.log(that.data.inputContent)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})